﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gate : MonoBehaviour {

    public string SceneName;
    private LoadingPanel LoadingPanel;

	// Use this for initialization
	void Start () {
        this.LoadingPanel = GameObject.Find("LoadingPanel").GetComponent<LoadingPanel>();
        UIHelper.ShowModelTitle(gameObject, "传送门", 0, 1.5f, 0);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnTriggerEnter(Collider other) {
        GlobalData globalData = GlobalData.Instance;
        if (other.CompareTag("Player")) { // 碰到主角
            if (globalData.IsEscaping) { // 正在逃跑
                globalData.IsEscaping = false;
                return;
            } else {
                globalData.IsEscaping = true;
            }
            GameManager.Instance.UpdatePlayer(this.transform.position, other.transform.eulerAngles);
            this.LoadingPanel.LoadScene(this.SceneName);
        }
    }
}
